cmake_minimum_required(VERSION 3.0)

#set(VCPKG_ROOT "/home/ahri/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE PATH "")
#set(CMAKE_TOOLCHAIN_FILE ${VCPKG_ROOT})

project(145PROJECT VERSION 1.0.0 LANGUAGES C CXX)

# 设置编译选项
add_compile_options(-Wall -Wextra -pedantic)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe -std=c++11")
set(CMAKE_BUILD_TYPE "Debug")





# 使用 find_package 查找 Boost 库
INCLUDE_DIRECTORIES(/usr/local/include/boost)
set(Boost_USE_STATIC_LIBS ON)
#set(BOOST_ROOT /usr/local) # 设置boost库搜索路径
#set(Boost_NO_SYSTEM_PATHS ON) # 只搜索上语句设置的搜索路径

find_package(Boost REQUIRED)

#if(Boost_FOUND)
#    include_directories(${Boost_INCLUDE_DIRS})
    
#    MESSAGE( STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}.")
#    MESSAGE( STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}.")
#    MESSAGE( STATUS "Boost_LIB_VERSION = ${Boost_LIB_VERSION}.")
#endif()

set(jsoncpp_LIBRARIES /home/ahri/Desktop/jsoncpp-master/build/lib/libjsoncpp.a)
#find_package(jsoncpp REQUIRED)
#if(jsoncpp_FOUND)
#    include_directories(${jsoncpp_INCLUDE_DIRS})
#    
#    MESSAGE( STATUS "jsoncpp_INCLUDE_DIRS = ${jsoncpp_INCLUDE_DIRS}.")
#    MESSAGE( STATUS "jsoncpp_LIBRARIES = ${jsoncpp_LIBRARIES}.")
#    MESSAGE( STATUS "jsoncpp_LIB_VERSION = ${jsoncpp_LIB_VERSION}.")
#endif()


set(OPENSSL_LIBRARIES /usr/local/lib/libssl.a)
#find_library(OPENSSL_LIBRARIES
#    NAMES ssl crypto
#    HINTS /usr/local/lib  # 指定搜索路径
    #PATH_SUFFIXES lib64  # 如果使用的是64位系统，可能需要添加此后缀
#)
#if(OPENSSL_LIBRARIES)
#    message(STATUS "Found openssl library: ${OPENSSL_LIBRARIES}")
#endif()
set(curl_LIBRARIES /usr/local/lib/libcurl.a)
#set(curl_LIBRARIES /home/ahri/vcpkg/installed/x64-linux/lib/libcurl.a)
#find_library(curl_LIBRARIES
#    NAMES curl  # 库的名称（例如libmylibrary.so）
#    HINTS /home/ahri/vcpkg/installed/x64-linux/lib  # 库的具体路径
#    PATH_SUFFIXES lib64
#)
#if(curl_LIBRARIES)
#    message(STATUS "Found curl library: ${curl_LIBRARIES}")
#endif()
set(hiredis_LIBRARIES /usr/local/lib/libhiredis.a)


# 包含头文件目录
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/element/module/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/element/sln/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/element/syncd/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

##--------------------- Source files ---------------------------------------##
#file(GLOB_RECURSE MOUDLE_LIB ${CMAKE_CURRENT_SOURCE_DIR}/element/module/*.o)
file(GLOB_RECURSE SYNCD_LIB ${CMAKE_CURRENT_SOURCE_DIR}/element/syncd/*.o)
file(GLOB_RECURSE SLN_LIB ${CMAKE_CURRENT_SOURCE_DIR}/element/sln/*.o)
file(GLOB_RECURSE SRC_LIB ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)

#这是需要排除的main.o文件`
set(EXCLUDE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/element/sln/main.o)

# `从 SLN_LIB 列表中排除指定的文件`
list(REMOVE_ITEM SLN_LIB ${EXCLUDE_FILES})

# 添加源文件
add_executable(sln_LOGO
    main/main.cpp
)

add_library(source_lib STATIC  ${SYNCD_LIB} ${SLN_LIB} ${SRC_LIB})


#添加头文件路径
target_include_directories(sln_LOGO PRIVATE #/home/ahri/vcpkg/installed/x64-linux/include/json
#    /home/ahri/vcpkg/installed/x64-linux/include/curl
    /usr/local/include/openssl
    /usr/local/include/boost)


# 将库链接到目标
target_link_libraries(sln_LOGO source_lib)
target_link_libraries(sln_LOGO ${Boost_LIBRARIES})
target_link_libraries(sln_LOGO ${jsoncpp_LIBRARIES})
target_link_libraries(sln_LOGO ${OPENSSL_LIBRARIES} crypto)
target_link_libraries(sln_LOGO ${curl_LIBRARIES})
target_link_libraries(sln_LOGO ${hiredis_LIBRARIES})
target_link_libraries(sln_LOGO -lpthread)
target_link_libraries(sln_LOGO -lstdc++ -lgcc)
target_link_libraries(sln_LOGO -lz)


# 设置编译选项，将生成的可执行文件静态链接
set_target_properties(sln_LOGO PROPERTIES LINK_FLAGS "-static -fPIE")

# 需要添加静态版本的C++运行库
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")